home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1956 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: ix.netcom.com!netnews
  2. From: miker3@ix.netcom.com (Mike Rubenstein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: swap high and low 16 bits?
  5. Date: Thu, 18 Jan 1996 01:03:16 GMT
  6. Organization: Netcom
  7. Message-ID: <30fd96d2.20527936@nntp.ix.netcom.com>
  8. References: <Pine.OSF.3.91.960115174921.19742A-100000@io.UWinnipeg.ca> <4dfeko$phv@nntp.crl.com> <Pine.OSF.3.91.960117085702.29067B-100000@io.UWinnipeg.ca>
  9. NNTP-Posting-Host: ix-dc10-12.ix.netcom.com
  10. X-NETCOM-Date: Wed Jan 17  5:03:12 PM PST 1996
  11. X-Newsreader: Forte Agent .99c/16.141
  12.  
  13. Bill Simpson <wsimpson@uwinnipeg.ca> wrote:
  14.  
  15. |>On 16 Jan 1996, Bruce Ivey wrote:
  16. |>
  17. |>> Bill Simpson (wsimpson@uwinnipeg.ca) wrote:
  18. |>> : I wanted to obtain a "random" starting number each time a
  19. program
  20. |>> : is run.  The obvious choice is time(NULL).  The problem with it
  21. is that
  22. |>> : if the program runs and terminates fairly quickly, the number
  23. returned by 
  24. |>> : time(NULL) is quite similar each run, differing only by the
  25. lowest bits.
  26. |>> 
  27. |>> Why not use a combination of values obtained from your system's
  28. time of day
  29. |>> instead of the time the program has been running?  Unless the
  30. program is
  31. |>> set to run at the same time every day, this should give good
  32. seeds.
  33. |>Well I guess you don't realize that time(NULL) returns the time (in
  34. sec from
  35. |>Jan 1 1970 or some such thing), not the duration the program has
  36. been
  37. |>running.
  38.  
  39. While this is true on some systems, it is not required by the
  40. standard.  From ISO 7.12.2.4:
  41.  
  42.     The time function determines the current calendar time.  The 
  43.     encoding of the value is unspecified.
  44.  
  45.  
  46. Michael M Rubenstein
  47.